package AirlineControl;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;

public class GUI extends JPanel{
	//Define Constants
	private final Border blackline = BorderFactory.createLineBorder(Color.black);
	private final String date = "yyyy-mm-dd";
	private final String time = "hhmm";
	private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
	private final String[] airplanes = {"Boeing 737", "Boeing 747", "Boeing 767", "Airbus 330", "Airbus 340", "Airbus 350", "Airbus 380"};
	private final String[] cities = {"-Choose One-", "New York, NY", "Washington, DC", "Baltimore, MD", "Los Angeles, CA", "San Francisco, CA", "Seattle, WA", "Chicago, IL", "Newark, NJ", "Detroit, MI", "Boston, MA", "Raleigh, NC", "Tucson, AZ", "Columbus, OH", "Tampa, FL", "Houston, TX", "Las Vegas, NV", "Minneapolis, MN", "Atlanta, GA", "Pittsburg, PA", "Toronto, ON"};
	private final String[] classes = {"First Class", "Business Class", "Economoy Class"};
	
	//Helpful grid thing
	private GridBagConstraints c = new GridBagConstraints();
	
	//Create ButtonGroup
	ButtonGroup direct = new ButtonGroup();
	
	//Array of existing flight numbers
	private String[] flightNums = {"None"};

	//Create objects for Schedule a Flight
	private JLabel JLDate = new JLabel("Date");
	private JLabel JLFlightNum = new JLabel("Flight Number");
	private JLabel JLPlane = new JLabel("Aircraft Type");
	private JLabel JLSource = new JLabel("Leaving From");
	private JLabel JLDest = new JLabel("Destination");
	private JLabel JLDirect = new JLabel("Direct Flight?");
	private JLabel JLIntermediate = new JLabel("Intermediate Stops");
	private JLabel JLDepartTime = new JLabel("Departure Time");
	private JLabel JLArriveTime = new JLabel("Arrival Time");
	private JLabel JLDepartDate = new JLabel("Departure Date");
	private JLabel JLArriveDate = new JLabel("Arrival Date");
	
	private JTextField JTFFlightNumSched = new JTextField(8);
	private JTextField JTFDate = new JTextField(date, 10);
	private JTextField JTFDepartTime = new JTextField(time, 5);
	private JTextField JTFDepartDate = new JTextField(date, 10);
	private JTextField JTFArriveTime = new JTextField(time, 5);
	private JTextField JTFArriveDate = new JTextField(date, 10);
	
	private JComboBox JCBPlane = new JComboBox(airplanes);
	private JComboBox JCBSource = new JComboBox(cities);
	private JComboBox JCBDest = new JComboBox(cities);
	private JComboBox JCBInt1 = new JComboBox(cities);
	private JComboBox JCBInt2 = new JComboBox(cities);
	
	private JRadioButton JRBYes = new JRadioButton("Yes", true);
	private JRadioButton JRBNo = new JRadioButton("No", false);
	
	private JButton JBSchedule = new JButton("Schedule Flight");
	
	//Create objects for Book a Flight
	private JLabel JLFlightNumBook = new JLabel("Flight Number");
	private JLabel JLDateBook = new JLabel("Date");
	private JLabel JLSSN = new JLabel("SSN");
	private JLabel JLName = new JLabel("Name");
	private JLabel JLAge = new JLabel("Age");
	private JLabel JLClass = new JLabel("Flight Class");
	private JLabel JLSeatNum = new JLabel("Seat Number");
	private JLabel JLPaid = new JLabel("Amount Paid");
	private JLabel JLNumBags = new JLabel("Number of Bags");
	private JLabel JLStreet = new JLabel("Street");
	private JLabel JLAptNum = new JLabel("Apartment Number");
	private JLabel JLCity = new JLabel("City");
	private JLabel JLState = new JLabel("State");
	private JLabel JLZip = new JLabel("Zip Code");
	private JLabel JLPhone = new JLabel("Phone Number");
	private JLabel JLEmail = new JLabel("Email");
	
	private JTextField JTFDateBook = new JTextField(date, 10);
	private JTextField JTFSSN = new JTextField(11);
	private JTextField JTFName = new JTextField(26);
	private JTextField JTFAge = new JTextField(3);
	private JTextField JTFSeatNum = new JTextField(4);
	private JTextField JTFPaid = new JTextField(8);
	private JTextField JTFNumBags = new JTextField(3);
	private JTextField JTFStreet = new JTextField(30);
	private JTextField JTFAptNum = new JTextField(5);
	private JTextField JTFCity = new JTextField(14);
	private JTextField JTFState = new JTextField(2);
	private JTextField JTFZip = new JTextField(5);
	private JTextField JTFPhone = new JTextField(10);
	private JTextField JTFEmail = new JTextField(20);
	
	private JComboBox JCBFlightNumBook = new JComboBox(flightNums);
	private JComboBox JCBClass = new JComboBox(classes);
	
	private JButton JBBook = new JButton("Book Flight");
	
	//Create objects for Edit Flight
	private JLabel JLFlightNumEdit = new JLabel("Flight Number");
	private JLabel JLDepartTimeEdit = new JLabel("Departure Time");
	private JLabel JLArriveTimeEdit = new JLabel("Arrival Time", JLabel.RIGHT);
	private JLabel JLDepartDateEdit = new JLabel("Departure Date");
	private JLabel JLArriveDateEdit = new JLabel("Arrival Date", JLabel.RIGHT);
	
	private JTextField JTFDepartTimeEdit = new JTextField(time, 5);
	private JTextField JTFDepartDateEdit = new JTextField(date, 10);
	private JTextField JTFArriveTimeEdit = new JTextField(time, 5);
	private JTextField JTFArriveDateEdit = new JTextField(date, 10);
	
	private JComboBox JCBFlightNumEdit = new JComboBox(flightNums);
	
	private JButton JBEdit = new JButton("Edit Flight");
	
	//Create objects for Checkin
	private JLabel JLSSNCheck = new JLabel("SSN");
	private JLabel JLNumBagsCheck = new JLabel("Number of Bags");
	private JLabel JLSeatNumCheck = new JLabel("Seat Number");
	
	private JTextField JTFSSNCheck = new JTextField(11);
	private JTextField JTFNumBagsCheck = new JTextField(3);
	private JTextField JTFSeatNumCheck = new JTextField(4);
	
	private JButton JBCheckin = new JButton("Check In");
	
	//Create objects for Flight Information
	private JLabel JLFlightNumArrive = new JLabel("Flight Number");
	private JLabel JLNumPassengers = new JLabel("Number of Passengers");
	private JLabel JLNumStops = new JLabel("Number of Stops");
	private JLabel JLTimeTaken = new JLabel("Total Time Taken");
	private JLabel JLFlightNumTakeoff = new JLabel("Flight Number");
	
	private JTextField JTFNumPassengers = new JTextField(3);
	private JTextField JTFNumStops = new JTextField(3);
	private JTextField JTFTimeTaken = new JTextField(5);
	
	private JComboBox JCBFlightNumArrive = new JComboBox(flightNums);
	private JComboBox JCBFlightNumTakeoff = new JComboBox(flightNums);
	
	private JButton JBArrived = new JButton("Flight Arrived");
	private JButton JBTakeoff = new JButton("Permission to Takeoff");
	
	public GUI(){
		//Create tabbed pane
		final JTabbedPane basePanel = new JTabbedPane();
		
		//Create tabs for the tabbed pane
		JPanel JPSchedule = new JPanel();
		JPanel JPBook = new JPanel();
		JPanel JPEdit = new JPanel();
		JPanel JPCheckin = new JPanel();
		JPanel JPControl = new JPanel();
		
		//Create sub-panels for aesthetic appeal
		JPanel JPSubSchedule1 = new JPanel();
		JPanel JPSubSchedule2 = new JPanel();
		JPanel JPSubSchedule3 = new JPanel();
		JPanel JPSubSchedule4 = new JPanel();
		JPanel JPSubSchedule5 = new JPanel();
		JPanel JPSubSchedule6 = new JPanel();
		JPanel JPSubBook1 = new JPanel();
		JPanel JPSubBook2 = new JPanel();
		JPanel JPSubBook3 = new JPanel();
		JPanel JPSubBook4 = new JPanel();
		JPanel JPSubBook5 = new JPanel();
		JPanel JPSubBook6 = new JPanel();
		JPanel JPSubBook7 = new JPanel();
		JPanel JPSubEdit1 = new JPanel();
		JPanel JPSubEdit2 = new JPanel();
		JPanel JPSubEdit3 = new JPanel();
		JPanel JPSubCheckin1 = new JPanel();
		JPanel JPSubCheckin2 = new JPanel();
		JPanel JPSubCheckin3 = new JPanel();
		JPanel JPArrive = new JPanel();
		JPanel JPSubArrive1 = new JPanel();
		JPanel JPSubArrive2 = new JPanel();
		JPanel JPTakeoff = new JPanel();
		
		//Edit objects for aesthetic appeal
		JLDest.setPreferredSize(new Dimension(94, 10));
		JLArriveTime.setPreferredSize(new Dimension(110, 10));
		JLArriveDate.setPreferredSize(new Dimension(110, 10));
		JLArriveTimeEdit.setPreferredSize(new Dimension(110, 10));
		JLArriveDateEdit.setPreferredSize(new Dimension(110, 10));
		
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 0.5;
		c.weighty = 1.0;
		c.gridx = 0;
		
		//Manipulate layouts
		this.setLayout(new BorderLayout());
		this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		
		JPSchedule.setBorder(BorderFactory.createTitledBorder(blackline, "Schedule a Flight"));
		JPSchedule.setLayout(new GridBagLayout());
		JPSubSchedule1.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubSchedule2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubSchedule3.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubSchedule4.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubSchedule5.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubSchedule6.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		
		JPBook.setBorder(BorderFactory.createTitledBorder(blackline, "Book a Flight"));
		JPBook.setLayout(new GridBagLayout());
		JPSubBook1.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook3.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook4.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook5.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook6.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubBook7.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		
		JPEdit.setBorder(BorderFactory.createTitledBorder(blackline, "Edit Flight Information"));
		JPEdit.setLayout(new GridLayout(6, 1, 0, 0));
		JPSubEdit1.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubEdit2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubEdit3.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		
		JPCheckin.setBorder(BorderFactory.createTitledBorder(blackline, "Passenger Checkin"));
		JPCheckin.setLayout(new GridLayout(11, 1, 0, 0));
		JPSubCheckin1.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubCheckin2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubCheckin3.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		
		JPControl.setBorder(BorderFactory.createTitledBorder(blackline, "Flight Control"));
		JPControl.setLayout(new GridLayout(2, 1, 0, 8));
		JPArrive.setBorder(BorderFactory.createTitledBorder(blackline, "Arrival Information"));
		JPArrive.setLayout(new GridLayout(2, 1, 0, 0));
		JPSubArrive1.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPSubArrive2.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		JPTakeoff.setBorder(BorderFactory.createTitledBorder(blackline, "Takeoff Permission"));
		JPTakeoff.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
		
		direct.add(JRBYes);
		direct.add(JRBNo);
		
		//Add objects to the Schedule panel
		JPSubSchedule1.add(JLFlightNum);
		JPSubSchedule1.add(JTFFlightNumSched);
		JPSubSchedule1.add(JLDate);
		JPSubSchedule1.add(JTFDate);
		JPSubSchedule1.add(JLPlane);
		JPSubSchedule1.add(JCBPlane);
		c.ipady = 20;
		c.gridy = 0;
		JPSchedule.add(JPSubSchedule1, c);
		
		JPSubSchedule2.add(JLSource);
		JPSubSchedule2.add(JCBSource);
		c.ipady = 0;
		c.gridy = 1;
		JPSchedule.add(JPSubSchedule2, c);
		
		JPSubSchedule3.add(JLDest);
		JPSubSchedule3.add(JCBDest);
		c.gridy = 2;
		JPSchedule.add(JPSubSchedule3, c);
		
		JPSubSchedule4.add(JLDirect);
		JPSubSchedule4.add(JRBYes);
		JPSubSchedule4.add(JRBNo);
		c.gridy = 3;
		JPSchedule.add(JPSubSchedule4, c);
		
		JPSubSchedule5.add(JLIntermediate);
		c.gridy = 4;
		JPSchedule.add(JPSubSchedule5, c);
		
		JPSubSchedule6.add(JCBInt1);
		JPSubSchedule6.add(JCBInt2);
		JPSubSchedule6.add(JLDepartTime);
		JPSubSchedule6.add(JTFDepartTime);
		JPSubSchedule6.add(JLDepartDate);
		JPSubSchedule6.add(JTFDepartDate);
		JPSubSchedule6.add(JLArriveTime);
		JPSubSchedule6.add(JTFArriveTime);
		JPSubSchedule6.add(JLArriveDate);
		JPSubSchedule6.add(JTFArriveDate);
		JPSubSchedule6.add(JBSchedule);
		c.ipady = 130;
		c.gridy = 5;
		JPSchedule.add(JPSubSchedule6, c);
		
		//Add objects to the Book panel
		JPSubBook1.add(JLFlightNumBook);
		JPSubBook1.add(JCBFlightNumBook);
		JPSubBook1.add(JLDateBook);
		JPSubBook1.add(JTFDateBook);
		c.ipady = 0;
		c.gridy = 0;
		JPBook.add(JPSubBook1, c);
		
		JPSubBook2.add(JLSSN);
		JPSubBook2.add(JTFSSN);
		c.gridy = 1;
		JPBook.add(JPSubBook2, c);
		
		JPSubBook3.add(JLName);
		JPSubBook3.add(JTFName);
		JPSubBook3.add(JLAge);
		JPSubBook3.add(JTFAge);
		JPSubBook3.add(JLClass);
		JPSubBook3.add(JCBClass);
		JPSubBook3.add(JLSeatNum);
		JPSubBook3.add(JTFSeatNum);
		JPSubBook3.add(JLPaid);
		JPSubBook3.add(JTFPaid);
		JPSubBook3.add(JLNumBags);
		JPSubBook3.add(JTFNumBags);
		c.ipady = 50;
		c.gridy = 2;
		JPBook.add(JPSubBook3, c);
		
		JPSubBook4.add(JLStreet);
		JPSubBook4.add(JTFStreet);
		JPSubBook4.add(JLAptNum);
		JPSubBook4.add(JTFAptNum);
		JPSubBook4.add(JLCity);
		JPSubBook4.add(JTFCity);
		JPSubBook4.add(JLState);
		JPSubBook4.add(JTFState);
		JPSubBook4.add(JLZip);
		JPSubBook4.add(JTFZip);
		c.gridy = 3;
		JPBook.add(JPSubBook4, c);
		
		JPSubBook5.add(JLPhone);
		JPSubBook5.add(JTFPhone);
		c.ipady = 0;
		c.gridy = 4;
		JPBook.add(JPSubBook5, c);c.fill = GridBagConstraints.HORIZONTAL;
		
		JPSubBook6.add(JLEmail);
		JPSubBook6.add(JTFEmail);
		c.gridy = 5;
		JPBook.add(JPSubBook6, c);
		
		JPSubBook7.add(JBBook);
		c.gridy = 6;
		JPBook.add(JPSubBook7, c);
		
		//Add objects to the Edit panel
		JPSubEdit1.add(JLFlightNumEdit);
		JPSubEdit1.add(JCBFlightNumEdit);
		JPEdit.add(JPSubEdit1);
		
		JPSubEdit2.add(JLDepartTimeEdit);
		JPSubEdit2.add(JTFDepartTimeEdit);
		JPSubEdit2.add(JLDepartDateEdit);
		JPSubEdit2.add(JTFDepartDateEdit);
		JPSubEdit2.add(JLArriveTimeEdit);
		JPSubEdit2.add(JTFArriveTimeEdit);
		JPSubEdit2.add(JLArriveDateEdit);
		JPSubEdit2.add(JTFArriveDateEdit);
		JPEdit.add(JPSubEdit2);
		
		JPSubEdit3.add(JBEdit);
		JPEdit.add(JPSubEdit3);
		
		//Add objects to the Checkin panel
		JPSubCheckin1.add(JLSSNCheck);
		JPSubCheckin1.add(JTFSSNCheck);
		JPSubCheckin1.add(JLNumBagsCheck);
		JPSubCheckin1.add(JTFNumBagsCheck);
		JPCheckin.add(JPSubCheckin1);
		
		JPSubCheckin2.add(JLSeatNumCheck);
		JPSubCheckin2.add(JTFSeatNumCheck);
		JPCheckin.add(JPSubCheckin2);
		
		JPSubCheckin3.add(JBCheckin);
		JPCheckin.add(JPSubCheckin3);
		
		//Add objects to the Flight Control
		JPSubArrive1.add(JLFlightNumArrive);
		JPSubArrive1.add(JCBFlightNumArrive);
		JPSubArrive1.add(JBArrived);
		JPArrive.add(JPSubArrive1);
		
		JTFNumPassengers.setEditable(false);
		JTFNumStops.setEditable(false);
		JTFTimeTaken.setEditable(false);
		
		JPSubArrive2.add(JLNumPassengers);
		JPSubArrive2.add(JTFNumPassengers);
		JPSubArrive2.add(JLNumStops);
		JPSubArrive2.add(JTFNumStops);
		JPSubArrive2.add(JLTimeTaken);
		JPSubArrive2.add(JTFTimeTaken);
		JPArrive.add(JPSubArrive2);
		
		JPTakeoff.add(JLFlightNumTakeoff);
		JPTakeoff.add(JCBFlightNumTakeoff);
		JPTakeoff.add(JBTakeoff);
		
		JPControl.add(JPTakeoff);
		JPControl.add(JPArrive);
		
		//Add tabs to basePanel
		basePanel.addTab("Schedule", JPSchedule);
		basePanel.addTab("Book", JPBook);
		basePanel.addTab("Edit", JPEdit);
		basePanel.addTab("Checkin", JPCheckin);
		basePanel.addTab("Flight Control", JPControl);
		
		//Add Change Listener to the tabbed panel
		basePanel.addChangeListener(new ChangeListener(){
	        public void stateChanged(ChangeEvent e) {
	        	Airplane plane = new Airplane();
	        	Integer[] flights1 = plane.onGround();
	        	Integer[] flights2 = plane.inAir();
	        	String[] flights = new String[flights1.length];
	        	
	        	for(int a = 0; a < flights1.length; a++){
	        		flights[a] = flights1[a].toString();
	        	}
	        	
	            if(basePanel.getSelectedIndex() == 1){
	            	JCBFlightNumBook.setModel(new DefaultComboBoxModel(flights));
	            }
	            else if(basePanel.getSelectedIndex() == 2){
					JCBFlightNumEdit.setModel(new DefaultComboBoxModel(flights));
				}
	            else if(basePanel.getSelectedIndex() == 4){
	            	JCBFlightNumTakeoff.setModel(new DefaultComboBoxModel(flights));
	            	
	            	flights = new String[flights2.length];
	            	
	            	for(int a = 0; a < flights2.length; a++){
		        		flights[a] = flights2[a].toString();
		        	}
	            	
	            	JCBFlightNumArrive.setModel(new DefaultComboBoxModel(flights));
	            }
	        };
		});
		
		//Add action listeners
		JBSchedule.addActionListener(new ButtonListener());
		JBBook.addActionListener(new ButtonListener());
		JBEdit.addActionListener(new ButtonListener());
		JBCheckin.addActionListener(new ButtonListener());
		JBArrived.addActionListener(new ButtonListener());
		JBTakeoff.addActionListener(new ButtonListener());
		
		//Add basePanel to the real base panel
		this.add(basePanel);
	}
	
	//Action listener
	private class ButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			String actionCommand = e.getActionCommand();
			
			if(actionCommand.equals("Schedule Flight")){
				//Create information arrays
				Date[] dates = new Date[3];
				Calendar[] dates2 = {Calendar.getInstance(), Calendar.getInstance(), Calendar.getInstance()};
				int[] nums = new int[7];
				String[] strings = new String[5];
				Airplane newPlane;
				
				//Insert information into arrays
				try {
					dates[0] = dateFormat.parse(JTFDate.getText());
					dates[1] = dateFormat.parse(JTFDepartDate.getText());
					dates[2] = dateFormat.parse(JTFArriveDate.getText());
					
					dates2[0].setTime(dates[0]);
					dates2[1].setTime(dates[1]);
					dates2[2].setTime(dates[2]);
				} catch (ParseException e1) {
					e1.printStackTrace();
				}
				
				nums[0] = new Integer(JTFFlightNumSched.getText());
				nums[1] = new Integer(JTFDepartTime.getText());
				nums[2] = new Integer(JTFArriveTime.getText());
				
				strings[0] = airplanes[JCBPlane.getSelectedIndex()];
				strings[1] = cities[JCBDest.getSelectedIndex()];
				strings[2] = cities[JCBSource.getSelectedIndex()];
				
				if(JRBYes.isSelected()){
					strings[3] = "None";
					strings[4] = "None";
				}
				else{
					if(JCBInt1.getSelectedIndex() == 0){
						strings[3] = "None";
					}
					else{
						strings[3] = cities[JCBInt1.getSelectedIndex()];
					}
					
					if(JCBInt2.getSelectedIndex() == 0){
						strings[4] = "None";
					}
					else{
						strings[4] = cities[JCBInt2.getSelectedIndex()];
					}
				}
				
				newPlane = new Airplane(dates2, nums, strings);
			}
			else if(actionCommand.equals("Book Flight")){
				//Create information arrays
				Date dates;
				Calendar dates2 = Calendar.getInstance();
				Airplane plane = new Airplane();
				int[] nums = new int[7];
				String[] strings = new String[7];
				Integer[] flights = plane.onGround();
        plane = new Airplane(flights[JCBFlightNumBook.getSelectedIndex()]);
        plane.incrementSeatsBooked();
				Passenger newPass;
				
				//Get information and store it
				try {
					dates = dateFormat.parse(JTFDateBook.getText());
					
					dates2.setTime(dates);
				} 
				catch (ParseException e1) {
					e1.printStackTrace();
				}
				
				nums[0] = new Integer(JTFSSN.getText());
				nums[1] = flights[JCBFlightNumBook.getSelectedIndex()];
				nums[2] = new Integer(JTFAge.getText());
				nums[3] = new Integer(JTFSeatNum.getText());
				nums[4] = JCBClass.getSelectedIndex() + 1;
				nums[5] = new Integer(JTFPaid.getText());
				nums[6] = new Integer(JTFNumBags.getText());
				
				strings[0] = JTFName.getText();
				strings[1] = JTFStreet.getText();
				strings[2] = JTFAptNum.getText();
				strings[3] = JTFCity.getText();
				strings[4] = JTFState.getText();
				strings[5] = JTFEmail.getText();
				strings[6] = JTFPhone.getText();
				
				newPass = new Passenger(nums, strings, dates2);
			}
			else if(actionCommand.equals("Edit Flight")){
				//Create storage variables
				Date depart, arrive;
				Calendar depart2 = Calendar.getInstance();
				Calendar arrive2 = Calendar.getInstance();
				int departTime = 0000;
				int arriveTime = 0000;
				Airplane plane = new Airplane();
				Integer[] flights = plane.onGround();
				plane = new Airplane(flights[JCBFlightNumEdit.getSelectedIndex()]);
				boolean departInfo = false;
				boolean arriveInfo = false;
				
				//Get and store information
				try{
					departTime = new Integer(JTFDepartTimeEdit.getText());
					depart = dateFormat.parse(JTFDepartDateEdit.getText());
					depart2.setTime(depart);
					departInfo = true;
				}
				catch(NumberFormatException e1){
					System.out.println("Departure information remains unchanged.");
				} catch (ParseException e1) {
					System.out.println("Departure information remains unchanged.");
				}
				try{
					arriveTime = new Integer(JTFArriveTimeEdit.getText());
					arrive = dateFormat.parse(JTFArriveDateEdit.getText());
					arrive2.setTime(arrive);
					arriveInfo = true;
				}
				catch(NumberFormatException e1){
					System.out.println("Arrival information remains unchanged.");
				}
				catch (ParseException e1) {
					System.out.println("Arrival information remains unchanged.");
				}
				
				if(departInfo){
					plane.changeDepartureInfo(depart2, departTime);
				}
				
				if(arriveInfo){
					plane.changeArrivalInfo(arrive2, arriveTime);
				}
			}
			else if(actionCommand.equals("Check In")){
				Passenger fred = new Passenger(new Integer(JTFSSNCheck.getText()));
				Airplane plane = new Airplane(fred.getFlightID());
				
				fred.checkIn(new Integer(JTFNumBagsCheck.getText()), new Integer(JTFSeatNumCheck.getText()));
				plane.addPassenger();
			}
			else if(actionCommand.equals("Flight Arrived")){
				Airplane plane = new Airplane();
				Integer[] planes = plane.inAir();
				plane = new Airplane(planes[JCBFlightNumArrive.getSelectedIndex()]);
				int[] values = plane.arrive();
				
				JTFNumPassengers.setText(new Integer(values[0]).toString());
				JTFNumStops.setText(new Integer(values[1]).toString());
				JTFTimeTaken.setText(new Integer(values[2]).toString());
			}
			else if(actionCommand.equals("Permission to Takeoff")){
				Airplane plane = new Airplane();
				Integer[] planes = plane.onGround();
				plane = new Airplane(planes[JCBFlightNumTakeoff.getSelectedIndex()]);
				
				plane.takeOff();
			}
		}
	}
}